package com.xw.unification.entity;


import com.xw.unification.interfaces.ResultCodeEnumResolvable;
import com.xw.unification.interfaces.ResultCodeEnumerable;

/**
 * @author qiwei
 */
public final class ResultCodeEnumDefaultResolver<E extends Enum<E>> implements ResultCodeEnumResolvable<E> {

    Class<E> enumType;

    public ResultCodeEnumDefaultResolver(Class<E> enumClass) {
        if (!ResultCodeEnumerable.class.isAssignableFrom(enumClass)) {
            throw new IllegalArgumentException("Parameter must be class of enum");
        }
        this.enumType = enumClass;
    }

    @Override
    public E nameOf(String name) {
        return Enum.valueOf(enumType, name);
    }

}
